/**
 * @see [description](https://docs.alipay.com/mini/api/ui-feedback)
 * confirm 确认框。
 * @param title [string] 标题
 * @param content [string] 内容
 * @param confirmButtonText [string] 确认按钮文字，默认确定
 * @param cancelButtonText [string] 确认按钮文字，默认取消
 * @example confirm('温馨提示','您是想查询快递单号','马上查询','暂不需要');
 */
export default function confirm(title?: string, content?: string, confirmButtonText?: string, cancelButtonText?: string) {
	const options = {};
	if (title !== undefined) {
		Object.assign(options, {
			title
		});
	}
	if (content !== undefined) {
		Object.assign(options, {
			content
		});
	}
	if (confirmButtonText !== undefined) {
		Object.assign(options, {
			confirmButtonText
		});
	}
	if (cancelButtonText !== undefined) {
		Object.assign(options, {
			cancelButtonText
		});
	}

	return new Promise<{
		msg: boolean;
		success: boolean
	}>((resolve, _reject) => {
		my.confirm({
			...options,
			success(res: any) {
				if (res.confirm) {
					resolve({
						msg: true,
						success: true
					});
				} else {
					resolve({
						msg: false,
						success: true
					});
				}
			},
			fail() {
				resolve({
					msg: false,
					success: false
				});
			}
		});
	});
}
